import { request, labelRequest } from '@/api/service'

export const urlDataPrefix = '/ai/datasets/'
export const urlLabelDataPrefix = '/api/projects/'

export function UploadJson (id, file) {
  return request({
    url: urlDataPrefix + 'uploadJson/',
    method: 'post',
    data: { id, file }
  })
}

export function HandleDataset (datasetID, datasetType) {
  return request({
    url: urlDataPrefix + 'handle/',
    method: 'get',
    params: { id: datasetID, type: datasetType }
  })
}

export function GetDatasets (query) {
  return labelRequest({
    url: urlLabelDataPrefix,
    method: 'get',
    params: { ...query }
  })
}

export function DelDataObj (id) {
  return labelRequest({
    url: urlLabelDataPrefix + id + '/',
    method: 'delete'
  })
}

export function ExportSnapshot (id) {
  return labelRequest({
    url: urlLabelDataPrefix + id + '/exports/',
    method: 'post'
  })
}

export function DownloadSnapshot (datasetID, exportID, exportType) {
  return labelRequest({
    url: urlLabelDataPrefix + datasetID + '/exports/' + exportID + '/download',
    method: 'get',
    params: { exportType: exportType }
  })
}

export function UpdateDataset (id, status) {
  return labelRequest({
    url: urlLabelDataPrefix + id,
    method: 'patch',
    data: { status }
  })
}
